/**
 * NOTICE OF LICENSE
 *
 * This source file is subject to the  Academic Free License (AFL 3.0)
 * that is available through the world-wide-web at this URL:
 * http://opensource.org/licenses/afl-3.0.php
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to support@zprofess.com so we can send you a copy immediately.
 *
 * @category   	Prestashop module
 * @package		Customer Point
 * @version 	1.0 (March 2012)
 * @author 		xuanhoapro <xuanhoapro@gmail.com>
 * @copyright   Copyright (c) 2011 ZPROFESS. (http://www.zprofess.com)
 * @license    	http://opensource.org/licenses/afl-3.0.php  Academic Free License (AFL 3.0)
 */
$(document).ready(function(){
	var body = $('body').attr('id');
	// add alias input when create account
	if (body == 'authentication' || body == 'order-opc'){
		$('#account-creation_form').submit(function(){
//		    var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;
//		    var emailblockReg = /^([\w-\.]+@(?!gmail.com)(?!yahoo.com)(?!hotmail.com)([\w-]+\.)+[\w-]{2,4})?$/;
			var pattern = new RegExp(/^(("[\w-+\s]+")|([\w-+]+(?:\.[\w-+]+)*)|("[\w-+\s]+")([\w-+]+(?:\.[\w-+]+)*))(@((?:[\w-+]+\.)*\w[\w-+]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$)|(@\[?((25[0-5]\.|2[0-4][\d]\.|1[\d]{2}\.|[\d]{1,2}\.))((25[0-5]|2[0-4][\d]|1[\d]{2}|[\d]{1,2})\.){2}(25[0-5]|2[0-4][\d]|1[\d]{2}|[\d]{1,2})\]?$)/i);
			var email_parent = $.trim($('#email_parent').val ());
			if(email_parent!=''){
				if(pattern.test(email_parent)){
					$.ajax({
						type: 'GET',
						url: baseDir + 'modules/zcustomerpoint/checkIdParentCustomer-ajax.php',
						data:"email_parent="+email_parent,
						async: true,
						cache: false,
						success: function(data)
						{
							if(data!=1){
								$('.error').remove();
								$("h1").after('<div class="error"><p>There is 1 error :</p><ol><li>Referer email is not exist.</li></ol></div>');
								window.scrollTo(10,10)
								return false;
							}else{
								return true;
							}
							
						}
					});
				}else{
					$('.error').remove();
					$("h1").after('<div class="error"><p>There is 1 error :</p><ol><li>Referer email is validate.</li></ol></div>');
					window.scrollTo(10,10)
					return false;
				}
			}
		});
		$("#days").parent().before('<p class="required text"><label for="email_parent">Referer email:</label><input type="text" class="text" id="email_parent" name="email_parent"><sup></sup></p>');
	}
});